package com.ktjy.mapper;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Demo1 {
    public static void main(String[] args) {
        try{

            Class cls = Class.forName("com.ktjy.pojo.Employee");
            Constructor constructor = cls.getDeclaredConstructor();
            Object obj = constructor.newInstance();

            Field empNo=cls.getDeclaredField("empNo");
            Field empName=cls.getDeclaredField("empName");
            Field empPost=cls.getDeclaredField("empPost");
            Field empSalary=cls.getDeclaredField("empSalary");

            empNo.setAccessible(true);
            empNo.set(obj,100);

            empName.setAccessible(true);
            empName.set(obj,"John");

            empPost.setAccessible(true);
            empPost.set(obj,"Mary");

            empSalary.setAccessible(true);
            empSalary.set(obj,2000);

            Method m=cls.getDeclaredMethod("showInfo");
            m.invoke(obj);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
